//
//  TabBarViewController.m
//  StandardizedProduct
//
//  Created by 宁宁 on 16/6/21.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "TabBarViewController.h"

#import "HomeViewController.h"
#import "CategoryViewController.h"
#import "CartViewController.h"
#import "MineViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    [self createTabBar];
    [self tabBarSetting];
    [self tabBarItemSetting];
    
}

- (void)createTabBar{
    HomeViewController *home = [[HomeViewController alloc] init];
    CategoryViewController *cate = [[CategoryViewController alloc] init];
    CartViewController *cart = [[CartViewController alloc] init];
    MineViewController *mine = [[MineViewController alloc] init];
    
    NSArray *controllerArray = @[home, cate, cart, mine];
    NSMutableArray *navArray = [NSMutableArray array];
    
    for (int i = 0; i < controllerArray.count; i++) {
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controllerArray[i]];
        
        nav.navigationBar.barTintColor = APPCOLOR;
        nav.navigationBar.tintColor = [UIColor whiteColor];
        nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont boldSystemFontOfSize:18]};
      
        
        [navArray addObject:nav];
    }
    
    self.viewControllers = navArray;
}


- (void)tabBarSetting{
    
//    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:10], NSForegroundColorAttributeName : APPCOLOR} forState:UIControlStateSelected];
    
    UITabBar *tabBar = self.tabBar;
    tabBar.barStyle = UIBarStyleBlack;
    tabBar.translucent = NO;
    tabBar.barTintColor = [UIColor whiteColor];
    tabBar.tintColor = APPCOLOR;
    
}

- (void)tabBarItemSetting{
    NSArray *viewControllers = self.viewControllers;
    
    UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"商城" image:[UIImage imageNamed:@"home"] tag:1];
    UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"分类" image:[UIImage imageNamed:@"categroy"] tag:2];
    UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"购物车" image:[UIImage imageNamed:@"cart"] tag:3];
    UITabBarItem *item4 = [[UITabBarItem alloc] initWithTitle:@"会员中心" image:[UIImage imageNamed:@"mine"] tag:4];
    
    HomeViewController *home = viewControllers[0];
    CategoryViewController *cate = viewControllers[1];
    CartViewController *cart = viewControllers[2];
    MineViewController *mine = viewControllers[3];
    
    home.tabBarItem = item1;
    cate.tabBarItem = item2;
    cart.tabBarItem = item3;
    mine.tabBarItem = item4;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
